home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / mac / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / DirectPlay / SimplePeer / frmApp.frm next >
Text File  |  2001-10-08  |  10KB  |  267 lines

  1. VERSION 5.00
  2. Begin VB.Form frmApp 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Session"
  5.    ClientHeight    =   4470
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   5400
  9.    Icon            =   "frmApp.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   4470
  14.    ScaleWidth      =   5400
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.CommandButton cmdExit 
  17.       Cancel          =   -1  'True
  18.       Caption         =   "Exit"
  19.       Height          =   315
  20.       Left            =   3383
  21.       TabIndex        =   9
  22.       Top             =   4020
  23.       Width           =   1035
  24.    End
  25.    Begin VB.Frame Rules 
  26.       Caption         =   "Rules"
  27.       Height          =   735
  28.       Left            =   60
  29.       TabIndex        =   5
  30.       Top             =   60
  31.       Width           =   5295
  32.       Begin VB.Label Label1 
  33.          BackStyle       =   0  'Transparent
  34.          Caption         =   $"frmApp.frx":0442
  35.          Height          =   435
  36.          Index           =   1
  37.          Left            =   60
  38.          TabIndex        =   6
  39.          Top             =   180
  40.          Width           =   5175
  41.       End
  42.    End
  43.    Begin VB.TextBox txtFace 
  44.       BackColor       =   &H8000000F&
  45.       Height          =   2295
  46.       Left            =   120
  47.       Locked          =   -1  'True
  48.       MultiLine       =   -1  'True
  49.       ScrollBars      =   2  'Vertical
  50.       TabIndex        =   4
  51.       Top             =   1620
  52.       Width           =   5235
  53.    End
  54.    Begin VB.CommandButton cmdMakeFace 
  55.       Caption         =   "Make Face"
  56.       Default         =   -1  'True
  57.       Height          =   315
  58.       Left            =   983
  59.       TabIndex        =   1
  60.       Top             =   4020
  61.       Width           =   1035
  62.    End
  63.    Begin VB.Frame Frame1 
  64.       Caption         =   "Game Status"
  65.       Height          =   735
  66.       Left            =   60
  67.       TabIndex        =   0
  68.       Top             =   840
  69.       Width           =   5295
  70.       Begin VB.Label lblPlayerName 
  71.          BackStyle       =   0  'Transparent
  72.          Height          =   255
  73.          Left            =   1980
  74.          TabIndex        =   8
  75.          Top             =   180
  76.          Width           =   3135
  77.       End
  78.       Begin VB.Label Label1 
  79.          BackStyle       =   0  'Transparent
  80.          Caption         =   "Local Player Name:"
  81.          Height          =   195
  82.          Index           =   2
  83.          Left            =   120
  84.          TabIndex        =   7
  85.          Top             =   180
  86.          Width           =   1935
  87.       End
  88.       Begin VB.Label lblPlayer 
  89.          BackStyle       =   0  'Transparent
  90.          Height          =   255
  91.          Left            =   2040
  92.          TabIndex        =   3
  93.          Top             =   420
  94.          Width           =   3075
  95.       End
  96.       Begin VB.Label Label1 
  97.          BackStyle       =   0  'Transparent
  98.          Caption         =   "Current number of players:"
  99.          Height          =   195
  100.          Index           =   0
  101.          Left            =   120
  102.          TabIndex        =   2
  103.          Top             =   420
  104.          Width           =   1935
  105.       End
  106.    End
  107. End
  108. Attribute VB_Name = "frmApp"
  109. Attribute VB_GlobalNameSpace = False
  110. Attribute VB_Creatable = False
  111. Attribute VB_PredeclaredId = True
  112. Attribute VB_Exposed = False
  113. Option Explicit
  114. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  115. '
  116. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  117. '
  118. '  File:       frmApp.frm
  119. '
  120. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  121. Implements DirectPlay8Event
  122. Private Const gbMSGFACE As Byte = 1
  123. Private msName As String
  124.  
  125. Private Sub cmdExit_Click()
  126.     Unload Me
  127. End Sub
  128.  
  129. Private Sub cmdMakeFace_Click()
  130.     Dim Buf() As Byte, lOffSet As Long
  131.     'For the purpose of this sample we don't care what the contents of the buffer
  132.     'will be.  Since there is only one application defined msg in this sample
  133.     'sending anything will suffice.
  134.     
  135.     If glNumPlayers > 1 Then 'Go ahead and send this to someone
  136.         lOffSet = NewBuffer(Buf)
  137.         AddDataToBuffer Buf, gbMSGFACE, SIZE_BYTE, lOffSet
  138.         dpp.SendTo DPNID_ALL_PLAYERS_GROUP, Buf, 0, DPNSEND_NOLOOPBACK
  139.     Else
  140.         UpdateText "There is no one to make faces at!!!"
  141.     End If
  142. End Sub
  143.  
  144. Private Sub Form_Load()
  145.     'Init our vars
  146.     InitDPlay
  147.     
  148.     Set DPlayEventsForm = New DPlayConnect
  149.     'First lets get the dplay connection started
  150.     If Not DPlayEventsForm.StartConnectWizard(dx, dpp, AppGuid, 10, Me) Then
  151.         Cleanup
  152.         End
  153.     End If
  154.     
  155.     gfHost = DPlayEventsForm.IsHost
  156.     msName = DPlayEventsForm.UserName
  157.     lblPlayerName.Caption = msName
  158.     If gfHost Then
  159.         Me.Caption = DPlayEventsForm.SessionName & " (HOST)"
  160.     End If
  161.     lblPlayer.Caption = CStr(glNumPlayers)
  162. End Sub
  163.  
  164. Private Sub Form_Unload(Cancel As Integer)
  165.     Cleanup
  166. End Sub
  167.  
  168. Private Sub UpdateText(ByVal sString As String)
  169.     'Update the chat window first
  170.     txtFace.Text = txtFace.Text & sString & vbCrLf
  171.     'Now limit the text in the window to be 16k
  172.     If Len(txtFace.Text) > 16384 Then
  173.         txtFace.Text = Right$(txtFace.Text, 16384)
  174.     End If
  175.     'Autoscroll the text
  176.     txtFace.SelStart = Len(txtFace.Text)
  177. End Sub
  178.  
  179. Private Sub DirectPlay8Event_AddRemovePlayerGroup(ByVal lMsgID As Long, ByVal lPlayerID As Long, ByVal lGroupID As Long, fRejectMsg As Boolean)
  180.     'VB requires that we must implement *every* member of this interface
  181. End Sub
  182.  
  183. Private Sub DirectPlay8Event_AppDesc(fRejectMsg As Boolean)
  184.     'VB requires that we must implement *every* member of this interface
  185. End Sub
  186.  
  187. Private Sub DirectPlay8Event_AsyncOpComplete(dpnotify As DxVBLibA.DPNMSG_ASYNC_OP_COMPLETE, fRejectMsg As Boolean)
  188.     'VB requires that we must implement *every* member of this interface
  189. End Sub
  190.  
  191. Private Sub DirectPlay8Event_ConnectComplete(dpnotify As DxVBLibA.DPNMSG_CONNECT_COMPLETE, fRejectMsg As Boolean)
  192.     Dim AppDesc As DPN_APPLICATION_DESC
  193.     
  194.     'Go ahead and put the session name in the title bar
  195.     AppDesc = dpp.GetApplicationDesc
  196.     Me.Caption = AppDesc.SessionName
  197. End Sub
  198.  
  199. Private Sub DirectPlay8Event_CreateGroup(ByVal lGroupID As Long, ByVal lOwnerID As Long, fRejectMsg As Boolean)
  200.     'VB requires that we must implement *every* member of this interface
  201. End Sub
  202.  
  203. Private Sub DirectPlay8Event_CreatePlayer(ByVal lPlayerID As Long, fRejectMsg As Boolean)
  204.     'Someone joined, increment the count
  205.     glNumPlayers = glNumPlayers + 1
  206.     lblPlayer.Caption = CStr(glNumPlayers)
  207. End Sub
  208.  
  209. Private Sub DirectPlay8Event_DestroyGroup(ByVal lGroupID As Long, ByVal lReason As Long, fRejectMsg As Boolean)
  210.     'VB requires that we must implement *every* member of this interface
  211. End Sub
  212.  
  213. Private Sub DirectPlay8Event_DestroyPlayer(ByVal lPlayerID As Long, ByVal lReason As Long, fRejectMsg As Boolean)
  214.     'Someone left, decrement the count
  215.     glNumPlayers = glNumPlayers - 1
  216.     lblPlayer.Caption = CStr(glNumPlayers)
  217. End Sub
  218.  
  219. Private Sub DirectPlay8Event_EnumHostsQuery(dpnotify As DxVBLibA.DPNMSG_ENUM_HOSTS_QUERY, fRejectMsg As Boolean)
  220.     'VB requires that we must implement *every* member of this interface
  221. End Sub
  222.  
  223. Private Sub DirectPlay8Event_EnumHostsResponse(dpnotify As DxVBLibA.DPNMSG_ENUM_HOSTS_RESPONSE, fRejectMsg As Boolean)
  224.     'VB requires that we must implement *every* member of this interface
  225. End Sub
  226.  
  227. Private Sub DirectPlay8Event_HostMigrate(ByVal lNewHostID As Long, fRejectMsg As Boolean)
  228.     Dim dpPeer As DPN_PLAYER_INFO
  229.     dpPeer = dpp.GetPeerInfo(lNewHostID)
  230.     If (dpPeer.lPlayerFlags And DPNPLAYER_LOCAL) = DPNPLAYER_LOCAL Then 'I am the new host
  231.         Me.Caption = Me.Caption & " (HOST)"
  232.     End If
  233. End Sub
  234.  
  235. Private Sub DirectPlay8Event_IndicateConnect(dpnotify As DxVBLibA.DPNMSG_INDICATE_CONNECT, fRejectMsg As Boolean)
  236.     'VB requires that we must implement *every* member of this interface
  237. End Sub
  238.  
  239. Private Sub DirectPlay8Event_IndicatedConnectAborted(fRejectMsg As Boolean)
  240.     'VB requires that we must implement *every* member of this interface
  241. End Sub
  242.  
  243. Private Sub DirectPlay8Event_InfoNotify(ByVal lMsgID As Long, ByVal lNotifyID As Long, fRejectMsg As Boolean)
  244.     'VB requires that we must implement *every* member of this interface
  245. End Sub
  246.  
  247. Private Sub DirectPlay8Event_Receive(dpnotify As DxVBLibA.DPNMSG_RECEIVE, fRejectMsg As Boolean)
  248.     'There is only one msg that can be sent in this sample
  249.     Dim sPeer As String
  250.     
  251.     sPeer = dpp.GetPeerInfo(dpnotify.idSender).Name
  252.     UpdateText sPeer & " is making funny faces at you, " & msName
  253. End Sub
  254.  
  255. Private Sub DirectPlay8Event_SendComplete(dpnotify As DxVBLibA.DPNMSG_SEND_COMPLETE, fRejectMsg As Boolean)
  256.     'VB requires that we must implement *every* member of this interface
  257. End Sub
  258.  
  259. Private Sub DirectPlay8Event_TerminateSession(dpnotify As DxVBLibA.DPNMSG_TERMINATE_SESSION, fRejectMsg As Boolean)
  260.     If dpnotify.hResultCode = DPNERR_HOSTTERMINATEDSESSION Then
  261.         MsgBox "The host has terminated this session.  This sample will now exit.", vbOKOnly Or vbInformation, "Exiting"
  262.     Else
  263.         MsgBox "This session has been lost.  This sample will now exit.", vbOKOnly Or vbInformation, "Exiting"
  264.     End If
  265.     DPlayEventsForm.CloseForm Me
  266. End Sub
  267.